<?php
/**
 * Created by PhpStorm.
 * User: ming
 * Date: 17-8-16
 * Time: 下午5:33
 */

$client = new swoole_client(SWOOLE_SOCK_TCP | SWOOLE_KEEP);

if (!$client->connect("127.0.0.1", 9501, 5)) {
    exit("connect failed. Error: {$client->errCode}\n");
}

fwrite(STDOUT, "请输入消息：");
$msg = trim(fgets(STDIN));
$client->send($msg) or die("数据发送失败");

//recv方法用于从服务器端接收数据
$data = $client->recv();
if (!$data) {
    die("recv failed.");
}
//echo $client->recv() or die('接收失败');
echo $data;

$client->close();